package com.dtjd.playcoinmonkey.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.dtjd.playcoinmonkey.bean.MeListBean;
import com.dtjd.playcoinmonkey.databinding.ItemMeBinding;
import com.dtjd.playcoinmonkey.databinding.ItemMeDividerBinding;
import com.dtjd.playcoinmonkey.R;
import java.util.List;

public class MeListAdapter extends ArrayAdapter<MeListBean> {
    private final Activity context;
    public MeListAdapter(Activity context, List<MeListBean> objects){
        super(context, R.layout.item_home,objects);
        this.context=context;
    }
    @SuppressLint("SetTextI18n")
    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        MeListBean meListBean = getItem(position);
        @SuppressLint("ViewHolder") ItemMeBinding itemMeBinding= ItemMeBinding.inflate(LayoutInflater.from(context));
        @SuppressLint("ViewHolder") ItemMeDividerBinding divider= ItemMeDividerBinding.inflate(LayoutInflater.from(context));
        if (meListBean.type==0){
            return divider.getRoot();
        }else {
            itemMeBinding.itemMeIcon.setImageResource(meListBean.icon);
            itemMeBinding.itemMeTitle.setText(meListBean.title);
            itemMeBinding.itemMeSubtitle.setText(meListBean.subTitle);
            if (itemMeBinding.itemMeSubtitle.getText().toString().equals("")){
                itemMeBinding.itemMeSubtitle.setVisibility(View.GONE);
            }else {
                itemMeBinding.itemMeSubtitle.setVisibility(View.VISIBLE);
            }
            if (meListBean.hasRightArrow){
                itemMeBinding.rightArrow.setVisibility(View.VISIBLE);
            }else {
                itemMeBinding.rightArrow.setVisibility(View.GONE);
            }
            itemMeBinding.itemMeRedDot.setVisibility(meListBean.hasRedDot?View.VISIBLE:View.GONE);
            return itemMeBinding.getRoot();
        }
    }
}
